home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / TwinOpus2 / REXX / DOpus / CopyFile.rexx next >
OS/2 REXX Batch file  |  1994-10-13  |  4KB  |  162 lines

  1. /*
  2.  *
  3.  * Copy file(s) with TwinExpres from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  */
  11.  
  12. DOpusPort   = 'DOPUS.1'
  13.  
  14. if ~show(l,"rexxsupport.library") then        
  15.     call addlib("rexxsupport.library",0,-30,0)
  16. if showlist('Ports', DOpusPort) = 0 then do
  17.    say 'Directory Opus Arexx port not found. Aborting.'
  18.    call CleanUp
  19. end
  20.  
  21. address 'DOPUS.1'
  22. options results
  23.  
  24. /* setup DOpus window and tell user what's happening */
  25. Busy on
  26. TopText "Copying selected files..."
  27.  
  28. /* Get the destenation path */
  29. OtherWindow
  30. 'Status 6 -1'
  31. GetEntry Result
  32. ToPath = Result
  33. if left(ToPath,1) = '*' then do
  34.    ToPath = SubStr(ToPath,2)
  35.    DoReread='TRUE'
  36. end
  37. else do
  38.    'Status 13 -1'
  39.    ToPath = result
  40.    if ToPath = '' then do
  41.       TopText "No destenation directory selected."
  42.       call CleanUp
  43.    end
  44.    DoReread='FALSE'
  45. end
  46. ToPath=Quote(ToPath)
  47. OtherWindow
  48.  
  49.  
  50. /* Get the current path and do file-copy, depending on the  */
  51. /* type of path (Twin-path or normal path)                  */
  52. 'Status 6 -1'
  53. GetEntry Result
  54. FilePath = Result
  55.  
  56. /* Twin-way */
  57. if left(FilePath,1) = '*' then do
  58.    FilePath = SubStr(FilePath,2)
  59.    GetSelectedAll
  60.    SelectedEntries = result
  61.    if SelectedEntries = 'RESULT' then do
  62.       TopText "No files selected."
  63.       call CleanUp
  64.    end
  65.    NumberOfEntries = words(SelectedEntries)
  66.    do EntryNumber = 1 to NumberOfEntries
  67.       Index = word(SelectedEntries, EntryNumber)
  68.       GetEntry Index+1
  69.       Entry = result
  70.       File = strip(left(Entry,25))
  71.       if right(FilePath,1) = ':' then
  72.          File = Quote(FilePath || File)
  73.       else
  74.          File = Quote(FilePath || '/' || File)
  75.       address command 'echo >PPipe: copy' File ToPath 'ALL'
  76.       selection = Index||' 0 0'
  77.       SelectEntry selection
  78.    end
  79. end
  80.  
  81. /* Normal way */
  82. else do
  83.    'Status 13 -1'
  84.    FilePath = result
  85.    if FilePath = '' then do
  86.       TopText "No source directory selected."
  87.       call CleanUp
  88.    end
  89.    'GetSelectedAll "|" -1'
  90.    SelectedEntries = result
  91.    if SelectedEntries = 'RESULT' then do
  92.       TopText "No files selected."
  93.       call CleanUp
  94.    end
  95.    NumberOfEntries = CountWords(SelectedEntries)
  96.    do EntryNumber = 1 to NumberOfEntries
  97.       File = GetWord(EntryNumber, SelectedEntries)
  98.       SelectFile Quote(File)
  99.       File = Quote(FilePath || File)
  100.       address command 'echo >PPipe: copy' File ToPath 'ALL'
  101.    end
  102. end
  103.  
  104.  
  105. TopText "Ready"
  106. 'DisplayDir -1'
  107. if DoReread='TRUE' then do
  108.    otherwindow
  109.    address AREXX "Rexx:DOpus/Reread.rexx"
  110. end
  111. call CleanUp
  112.  
  113. exit
  114.  
  115. /*---------------------------------------------------------------------------*/
  116.  
  117. CleanUp: /* Remove any files and exit */
  118.    Busy off
  119.    exit
  120. return
  121.  
  122. /*--------------------------------------------------------------------------*/
  123.  
  124. Quote: procedure /* add quotes to string */
  125.    parse arg string
  126. return '"'||string||'"'
  127.  
  128. /*--------------------------------------------------------------------------*/
  129.  
  130. GetWord: procedure /* get word from '|' separated string */
  131.  
  132.   parse arg number,words
  133.  
  134.   if(left(words,1) ~= '|') then
  135.      words = '|'||words
  136.   do i=1 to number
  137.      idx = index(words, '|');
  138.      words = substr(words, idx+1)
  139.   end
  140.   end = index(words, '|') - 1
  141.   if words = "" then
  142.      return ""
  143.  
  144.   ret_str = substr(words, 1, end)
  145. return ret_str
  146.  
  147. /*--------------------------------------------------------------------------*/
  148.  
  149. CountWords: procedure /* count words from '|' separated string */
  150.  
  151.    parse arg words
  152.  
  153.    count = 0
  154.    idx = index(words, '|')
  155.    do while idx ~= 0
  156.      count = count + 1
  157.      words = substr(words, idx+1)
  158.      idx = index(words, '|')
  159.    end
  160. return count
  161.  
  162.